<template>
  <div>
    <p>
      用户名：<input type="text" v-model="user">
    <input type="text" v-model="comment" placeholder='评论内容'>
    </p><br><br>
    <p><input type="button" value="提交" @click="ti"></p> 
  <div class="list-detail">
    <list :list="list"></list>
  </div>
  </div>
</template>
<script>
import List from "./List";
import axios from 'axios'
export default {
  name: "Parent",
  components: {List},
  data () {
    return {
      list: [],
      user:'',
      comment:'',
    }
  },
  created(){
      // axios({
      //       url:'http://127.0.0.1:8000/pinlun/',
      //       method:'get',
      //   }).then(resp=>{
      //     console.log(resp.data)
      //     this.list=resp.data
      //   })
      this.axios.get('http://127.0.0.1:8000/pinlun/')
        .then(resp=>{
            console.log(resp.data)
            this.list=resp.data
            this.$router.go(0)
        }).catch(error=>{
            console.log(error.response)
        })
  },
  methods:{
    ti(){
      const data = {
            user: this.user,
            comment: this.comment,
        }
        this.axios.post('http://127.0.0.1:8000/pinlun/',data)
        .then(resp=>{
            console.log(resp.data)
        }).catch(error=>{
            console.log(error.response)
        })
    }
  }
}
</script>
